package com.ebook.eboo.Controller;

import com.ebook.eboo.Service.userService;
import com.ebook.eboo.pojo.Page;
import com.ebook.eboo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class userController {
    @Autowired
    userService userService;

    @CrossOrigin
    @PostMapping(value = "api/findBy")
    @ResponseBody
    public User findByUsername(@RequestBody User user){
        return userService.getByusername(user.getUsername());
    }
    @CrossOrigin
    @PostMapping(value = "api/findAll")
    @ResponseBody
    public List<User> findAll(){
        List<User> userList = userService.getAll();
        return userList;
    }
    @CrossOrigin
    @PostMapping(value = "api/delete")
    @ResponseBody
    public void deleteUser(@RequestBody User user){
        userService.deleteUser(user.getUsername());
    }
    @CrossOrigin
    @PostMapping(value = "api/update")
    @ResponseBody
    public int update(@RequestBody User user){
        return userService.uodateUserById(user);
    }
}
